.class public Lorg/jboss/netty/handler/execution/ExecutionHandler;
.super Ljava/lang/Object;
.source "ExecutionHandler.java"

# interfaces
.implements Lorg/jboss/netty/channel/ChannelUpstreamHandler;
.implements Lorg/jboss/netty/channel/ChannelDownstreamHandler;
.implements Lorg/jboss/netty/util/ExternalResourceReleasable;


# annotations
.annotation runtime Lorg/jboss/netty/channel/ChannelHandler$Sharable;
.end annotation


# instance fields
.field private final executor:Ljava/util/concurrent/Executor;

.field private final handleDownstream:Z


# direct methods
.method public constructor <init>(Ljava/util/concurrent/Executor;)V
    .locals 1
    .parameter "executor"

    .prologue
    .line 119
    const/4 v0, 0x0

    invoke-direct {p0, p1, v0}, Lorg/jboss/netty/handler/execution/ExecutionHandler;-><init>(Ljava/util/concurrent/Executor;Z)V

    .line 120
    return-void
.end method

.method public constructor <init>(Ljava/util/concurrent/Executor;Z)V
    .locals 2
    .parameter "executor"
    .parameter "handleDownstream"

    .prologue
    .line 126
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 127
    if-nez p1, :cond_0

    .line 128
    new-instance v0, Ljava/lang/NullPointerException;

    const-string v1, "executor"

    invoke-direct {v0, v1}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 130
    :cond_0
    iput-object p1, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->executor:Ljava/util/concurrent/Executor;

    .line 131
    iput-boolean p2, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->handleDownstream:Z

    .line 132
    return-void
.end method


# virtual methods
.method public getExecutor()Ljava/util/concurrent/Executor;
    .locals 1

    .prologue
    .line 138
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->executor:Ljava/util/concurrent/Executor;

    return-object v0
.end method

.method public handleDownstream(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)V
    .locals 2
    .parameter "ctx"
    .parameter "e"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 161
    invoke-virtual {p0, p1, p2}, Lorg/jboss/netty/handler/execution/ExecutionHandler;->handleReadSuspend(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)Z

    move-result v0

    if-nez v0, :cond_0

    .line 162
    iget-boolean v0, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->handleDownstream:Z

    if-eqz v0, :cond_1

    .line 163
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->executor:Ljava/util/concurrent/Executor;

    new-instance v1, Lorg/jboss/netty/handler/execution/ChannelDownstreamEventRunnable;

    invoke-direct {v1, p1, p2}, Lorg/jboss/netty/handler/execution/ChannelDownstreamEventRunnable;-><init>(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V

    .line 168
    :cond_0
    :goto_0
    return-void

    .line 165
    :cond_1
    invoke-interface {p1, p2}, Lorg/jboss/netty/channel/ChannelHandlerContext;->sendDownstream(Lorg/jboss/netty/channel/ChannelEvent;)V

    goto :goto_0
.end method

.method protected handleReadSuspend(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)Z
    .locals 6
    .parameter "ctx"
    .parameter "e"

    .prologue
    const/4 v3, 0x1

    const/4 v4, 0x0

    .line 174
    instance-of v2, p2, Lorg/jboss/netty/channel/ChannelStateEvent;

    if-eqz v2, :cond_1

    move-object v0, p2

    .line 175
    check-cast v0, Lorg/jboss/netty/channel/ChannelStateEvent;

    .line 176
    .local v0, cse:Lorg/jboss/netty/channel/ChannelStateEvent;
    invoke-interface {v0}, Lorg/jboss/netty/channel/ChannelStateEvent;->getState()Lorg/jboss/netty/channel/ChannelState;

    move-result-object v2

    sget-object v5, Lorg/jboss/netty/channel/ChannelState;->INTEREST_OPS:Lorg/jboss/netty/channel/ChannelState;

    if-ne v2, v5, :cond_1

    invoke-interface {v0}, Lorg/jboss/netty/channel/ChannelStateEvent;->getValue()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Integer;

    invoke-virtual {v2}, Ljava/lang/Integer;->intValue()I

    move-result v2

    and-int/lit8 v2, v2, 0x1

    if-eqz v2, :cond_1

    .line 180
    invoke-interface {p1}, Lorg/jboss/netty/channel/ChannelHandlerContext;->getAttachment()Ljava/lang/Object;

    move-result-object v2

    if-eqz v2, :cond_0

    move v1, v3

    .line 181
    .local v1, readSuspended:Z
    :goto_0
    if-eqz v1, :cond_1

    .line 184
    invoke-interface {p2}, Lorg/jboss/netty/channel/ChannelEvent;->getFuture()Lorg/jboss/netty/channel/ChannelFuture;

    move-result-object v2

    invoke-interface {v2}, Lorg/jboss/netty/channel/ChannelFuture;->setSuccess()Z

    move v2, v3

    .line 190
    .end local v0           #cse:Lorg/jboss/netty/channel/ChannelStateEvent;
    .end local v1           #readSuspended:Z
    :goto_1
    return v2

    .restart local v0       #cse:Lorg/jboss/netty/channel/ChannelStateEvent;
    :cond_0
    move v1, v4

    .line 180
    goto :goto_0

    .end local v0           #cse:Lorg/jboss/netty/channel/ChannelStateEvent;
    :cond_1
    move v2, v4

    .line 190
    goto :goto_1
.end method

.method public handleUpstream(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)V
    .locals 2
    .parameter "context"
    .parameter "e"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 155
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/ExecutionHandler;->executor:Ljava/util/concurrent/Executor;

    new-instance v1, Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;

    invoke-direct {v1, p1, p2}, Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;-><init>(Lorg/jboss/netty/channel/ChannelHandlerContext;Lorg/jboss/netty/channel/ChannelEvent;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V

    .line 156
    return-void
.end method

.method public releaseExternalResources()V
    .locals 3

    .prologue
    .line 146
    invoke-virtual {p0}, Lorg/jboss/netty/handler/execution/ExecutionHandler;->getExecutor()Ljava/util/concurrent/Executor;

    move-result-object v0

    .line 147
    .local v0, executor:Ljava/util/concurrent/Executor;
    const/4 v1, 0x1

    new-array v1, v1, [Ljava/util/concurrent/Executor;

    const/4 v2, 0x0

    aput-object v0, v1, v2

    invoke-static {v1}, Lorg/jboss/netty/util/internal/ExecutorUtil;->terminate([Ljava/util/concurrent/Executor;)V

    .line 148
    instance-of v1, v0, Lorg/jboss/netty/util/ExternalResourceReleasable;

    if-eqz v1, :cond_0

    .line 149
    check-cast v0, Lorg/jboss/netty/util/ExternalResourceReleasable;

    .end local v0           #executor:Ljava/util/concurrent/Executor;
    invoke-interface {v0}, Lorg/jboss/netty/util/ExternalResourceReleasable;->releaseExternalResources()V

    .line 151
    :cond_0
    return-void
.end method
